package initial;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.TreeSet;

import utility.Int2long;

/**
 * Sort active userId from "edges4activeUsers"
 * @author D
 * 
 */

public class SortId {

	private static TreeSet<Integer> nodeSet = new TreeSet<Integer>();

	public static void loadData(String str) {
		String[] tokens = str.split("\t");
		int[] users = Int2long.long2ints(Long.parseLong(tokens[0]));
		nodeSet.add(users[0]);
		nodeSet.add(users[1]);
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		String inPath = "/home/ddxu/data/edges4activeUsers.txt";//args[0];
		String outPath = "/home/ddxu/data/activeUsers.txt";//args[1];
		
		//int i = Integer.parseInt(args[0]);
		
		String str;
		
		try {
			BufferedReader in = new BufferedReader(new FileReader(inPath));
			while((str = in.readLine()) != null) {
				loadData(str);
			}
			in.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		System.out.println(nodeSet.size());
		
		int num = 0;
		
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(outPath));
			for(Integer key : nodeSet) {
				out.write(key.toString());
				out.write("\t");
				num++;
				out.write(Integer.toString(num));
				out.newLine();
			}
			out.flush();
			out.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
